package charlie.shop.warehouse;

import com.charlie.db.TopProduct;
import jxl.CellView;
import jxl.write.WritableSheet;
import jxl.write.WriteException;

/**
 * Supporting functions for excel export
 * 
 * @author Vitaliy Mostipaka <imprtat@gmail.com>
 */
public class TopProductExport extends WriteExcel {

    /**
     * Create label
     * @param sheet sheet sheet to work with
     * @throws WriteException if an write error occurs
     */
    @Override
    protected void createLabel(WritableSheet sheet)
            throws WriteException {
        CellView view = new CellView();
        view.setSize(10000);
        sheet.setColumnView(0, view);
        addCaption(sheet, 0, 0, "Top most popular guitars");
        addCaption(sheet, 0, 1, "Name");
        addCaption(sheet, 1, 1, "Points");
        addCaption(sheet, 2, 1, "Cost");
    }

    /**
     * Write line of data into excel sheet
     * 
     * @param sheet sheet to work with
     * @param line current line
     * @param row current row
     * @throws WriteException if an write error occurs
     */
    @Override
    protected void writeDataLine(WritableSheet sheet, int line, Object row) throws WriteException {
        TopProduct product = (TopProduct) row;
        addLabel(sheet, 0, line + 2, product.getName());
        addLabel(sheet, 1, line + 2, String.valueOf(product.getPoints()));
        addLabel(sheet, 2, line + 2, String.valueOf(product.getCost()));
    }
}
